/**
 * 渠道商
 * */


(function () {
})();


//列表
function getList(v){
    var formData = {
        isauth: v,
        start: pages.start, limit: pages.limit,
    };
    $.ajax({
        type: apis.qdShopIndex.method,
        url: apis.qdShopIndex.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            indexHtml(d);
            $('#pageTotal').html(d.length);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//列表字符串
function indexHtml(d){
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].id + '</td>';
        h += '<td>' + d[i].parent_id + '</td>';
        h += '<td>' + d[i].nickname + '</td>';
        h += '<td>' + d[i].phone + '</td>';
        h += '<td>';
        if (d[i].avatarUrl == '') {
            h += '-';
        } else {
            h += '<img src="' + d[i].avatarUrl + '" height="50"/>';
        }
        h += '</td>';
        h += '<td>' + d[i].serial + '</td>';
        h += '<td>' + d[i].level + '</td>';
        h += '<td>' + d[i].parent_id + '</td>';
        h += '<td>' + d[i].balance + '</td>';
        h += '<td>' + d[i].auth_name + '</td>';
        h += '<td>' + d[i].uptime + '</td>';
        h += '<td class="f-14">';
        if (d[i].isauth == 0) {
            //h += '<a href="javascript:;" onclick="auth(' + d[i].id + ');">';
            //h += '审核';
            //h += '</a>';
            h += '<a href="javascript:;" onclick="auth_edit(\'等级审核\',\'shop-auth.html\', ' + d[i].id + ');">';
            h += '审核';
            h += '</a>';
        }
        h += ' <br/> ';
        h += '<a href="shop-recharge.html?uid=' + d[i].id + '">';
        h += '充值记录';
        h += '</a>';
        h += ' <br/> ';
        //h += '<a href="shop-cost.html?uid=' + d[i].id + '">';
        //h += '<a href="javascript:;" onclick="cost_pop(\'订单消费记录\',\'shop-cost.html\', ' + d[i].id + ');">';
        //h += '订单消费记录';
        //h += '</a>';
        h += '<a href="javascript:;" onclick="lay_bank(\'提现卡号\',\'shop-bank.html\', ' + d[i].id + ');">';
        h += '提现卡号';
        h += '</a>';
        h += ' <br/> ';
        h += '<a href="shop-tixian.html?uid=' + d[i].id + '">';
        h += '提现记录';
        h += '</a>';
        h += ' <br/> ';
        h += '<a href="shop-team.html?pid=' + d[i].id + '">';
        h += '团队';
        h += '</a>';
        h += '</td>';
        h += '</tr>';
    }
    $('tbody').html(h);
}


////审核
//function auth(id){
//    var msg = '确认要 <b style="color: green; font-size: 20px;">通过审核</b> 吗？';
//    layer.confirm(msg,function(index){
//        $.ajax({
//            type: apis.qdShopAuth.method,
//            url: apis.qdShopAuth.url,
//            data: { id: id },
//            success: function (res) {
//                console.log(res);
//                if (res.code < 0) {
//                    msgPop({msg: res.msg}); return
//                }
//                layer.msg('审核成功!',{icon: 1,time: 1000});
//                setTimeout(function(){
//                    top.location.reload();
//                }, 1000);
//            },
//            error: function () {
//                console.log('错误了！');
//            }
//        });
//    });
//}


//设置等级弹窗
function auth_edit(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,300);
}


//设置等级
function setLevel(){
    var formData = {
        id: id,
        level: $('#level').val(),
    };
    $.ajax({
        type: apis.qdShopAuth.method,
        url: apis.qdShopAuth.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            layer.msg('审核成功!',{icon: 1,time: 1000});
            setTimeout(function(){
                top.location.reload();
            }, 1000);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//充值列表
function rechargeList(uid){
    $.ajax({
        type: apis.qdShopRechargeList.method,
        url: apis.qdShopRechargeList.url,
        data: { uid: uid },
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                console.log(h);
                return
            }
            var d = res.data;
            h = '';
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].uname + '</td>';
                h += '<td>' + d[i].money + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '</tr>';
            }
            tbody.html(h);
            $('#pageTotal').html(d.length);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//提现列表
function tixianList(uid) {
    $.ajax({
        type: apis.qdShopTixianList.method,
        url: apis.qdShopTixianList.url,
        data: {uid: uid},
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                console.log(h);
                return
            }
            var d = res.data;
            h = '';
            for (i = 0; i < d.length; i++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].money + '</td>';
                h += '<td>' + d[i].uptime + '</td>';
                h += '</tr>';
            }
            tbody.html(h);
            $('#pageTotal').html(d.length);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}



//订单消费记录
function cost_pop(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,300);
}


//消费列表
function costList(uid){
    $.ajax({
        type: apis.qdShopCostList.method,
        url: apis.qdShopCostList.url,
        data: { uid: uid },
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                console.log(h);
                return
            }
            var d = res.data;
            h = '';
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].money + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '</tr>';
            }
            tbody.html(h);
            $('#pageTotal').html(d.length);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//团队列表
function teamList(pid){
    $.ajax({
        type: apis.qdShopTeamList.method,
        url: apis.qdShopTeamList.url,
        data: { pid: pid },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            teamHtml(d);
            $('#pageTotal').html(d.length);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//团队字符串
function teamHtml(d){
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].pname + '</td>';
        h += '<td>' + d[i].nickname + '</td>';
        h += '<td>' + d[i].phone + '</td>';
        h += '<td>';
        if (d[i].avatarUrl == '') {
            h += '-';
        } else {
            h += '<img src="' + d[i].avatarUrl + '" height="50"/>';
        }
        h += '</td>';
        h += '<td>' + d[i].serial + '</td>';
        h += '<td>' + d[i].level + '</td>';
        h += '<td>' + d[i].balance + '</td>';
        h += '<td>' + d[i].cost + '</td>';
        h += '<td>' + d[i].uptime + '</td>';
        h += '<td class="f-14">';
        h += '<a href="javascript:;" onclick="team_income(\'收益明细\',\'shop-team-cost-list.html\', ' + d[i].id + ');">';
        h += '收益明细';
        h += '</a>';
        h += '</td>';
        h += '</tr>';
    }
    $('tbody').html(h);
}



//团队收益明细
function team_income(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,h);
}


//团队收益明细列表
function teamCostList(uid){
    var formData = {
        uid: uid,
        start: pages.start, limit: pages.limit,
    };
    $.ajax({
        type: apis.qdShopTeamIncomeList.method,
        url: apis.qdShopTeamIncomeList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="5">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            var d = res.data;
            $('#pageTotal').html(d.length);
            h = '';
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].money + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '</tr>';
            }
            tbody.html(h);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//提现审核列表
function txAuthList(){
    $.ajax({
        type: apis.qdShopTxAuthList.method,
        url: apis.qdShopTxAuthList.url,
        data: {},
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            var d = res.data;
            h = '';
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].id + '</td>';
                h += '<td>' + d[i].uname + '</td>';
                h += '<td>' + d[i].phone + '</td>';
                h += '<td>' + d[i].bank_info + '</td>';
                h += '<td>' + d[i].amount + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '<td class="f-14">';
                if (d[i].status == 1) {
                    h += '<a href="javascript:;" onclick="auth_ok(' + d[i].id + ');">';
                    h += '通过';
                    h += '</a>';
                    h += ' &nbsp; ';
                    h += '<a href="javascript:;" onclick="auth_no(' + d[i].id + ');">';
                    h += '拒绝';
                    h += '</a>';
                } else {
                    h += '-';
                }
                h += '</td>';
                h += '</tr>';
            }
            tbody.html(h);
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//提现审核通过
function auth_ok(v){
    var msg = '确认要 <b style="color: green; font-size: 20px;">通过</b> 吗？';
    layer.confirm(msg,function(index){
        authApi({id: v, auth: 2});
    });
}
//提现审核拒绝
function auth_no(v){
    var msg = '确认要 <b style="color: red; font-size: 20px;">拒绝</b> 吗？';
    layer.confirm(msg,function(index){
        authApi({id: v, auth: 1});
    });
}
//提现审核API
function authApi(e){
    $.ajax({
        type: apis.qdShopTxAuthModify.method,
        url: apis.qdShopTxAuthModify.url,
        data: { id: e.id, auth: e.auth },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            layer.msg('操作成功!',{icon: 1,time: 50});
            setTimeout(function(){
                top.location.reload();
            }, 500);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//卡号弹窗
function lay_bank(title,url,id,w,h){
    url += '?uid=' + id;
    layer_show(title,url,w,h);
}


//卡号列表
function bankList(){
    var formData = {
        uid: uid,
        start: pages.start,
        limit: pages.limit,
    };
    $.ajax({
        type: apis.qdShopBankList.method,
        url: apis.qdShopBankList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            var d = res.data;
            h = '';
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].id + '</td>';
                h += '<td>' + d[i].uname + '</td>';
                h += '<td>' + d[i].realname + '</td>';
                h += '<td>' + d[i].phone + '</td>';
                h += '<td>' + d[i].bank_name + '</td>';
                h += '<td>' + d[i].card_no + '</td>';
                h += '<td>' + d[i].default + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '<td class="f-14">';
                if (d[i].is_default == 0) {
                    h += '<a href="javascript:;" onclick="toDefault(' + d[i].id + ');">';
                    h += '设为默认';
                    h += '</a>';
                } else {
                    h += '-';
                }
                h += '</td>';
                h += '</tr>';
            }
            tbody.html(h);
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//卡号默认设置
function toDefault(v){
    var msg = '确认要 <b style="color: green; font-size: 20px;">默认</b> 吗？';
    layer.confirm(msg,function(index){
        $.ajax({
            type: apis.qdShopBankDefaultModify.method,
            url: apis.qdShopBankDefaultModify.url,
            data: { id: v },
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    msgPop({msg: res.msg});
                    return
                }
                layer.msg('操作成功!',{icon: 1,time: 50});
                msgPop({msg: '操作成功'});
                setTimeout(function(){
                    location.reload();
                }, 500);
            },
            error: function () {
                console.log('错误了！');
            }
        });
    });
}